import {
  checkLogin
} from './auth.js'
new Vue({
  el: '#app',
  data: {
    IS_LOGIN: null,
    myChart: null,
    option: null,
    reoprtData: null
  },
  async created() {
    this.IS_LOGIN = await checkLogin()
    if (this.IS_LOGIN == null) {
      location.href = '/'
    }
    this.initMyChart()
  },
  methods: {
    // 获取报表数据
    async getReportData () {
      const res = await request.get('/order/getOrderReport')
      this.reoprtData = res.data
    },
    async initMyChart () {
      await this.getReportData()
      this.myChart = echarts.init(this.$refs.chart1)
      this.option = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {d}%",
        },
        legend: {
          orient: "vertical",
          left: "left",
          top: "center",
          data: this.reoprtData.xdata
        },
        series: [{
          name: "类目",
          type: "pie",
          radius: "55%",
          center: ["50%", "50%"],
          data: this.reoprtData.ydata,
          itemStyle: {
            emphasis: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: "rgba(0, 0, 0, 0.5)",
            },
          },
        }]
      }
      this.myChart.setOption(this.option)
    }
  }
})